﻿using System;
using System.Data.Entity;
using System.Linq;
using ZBJF.Warranty.Model;

namespace ZBJF.Warranty.BLL
{
    public partial class InsuranceProductSnapshootService
    {
        ///// <summary>
        ///// 产品订单的产品快照（保险产品）
        ///// </summary>
        ///// <param name="insuranceProductOrderID">销售订单ID</param>
        ///// <param name="insuranceProductOrderNo">订单号</param>
        ///// <param name="sellerInsuranceProductID">保险卡产品ID</param>
        ///// <returns></returns>
        //public bool CreateSnapshoot(long insuranceProductOrderID, string insuranceProductOrderNo, long sellerInsuranceProductID)
        //{
        //    var result = false;
        //    var sellerInsuranceProduct =
        //        ServiceFactory.SellerInsuranceProductsServiceInstance.LoadById(sellerInsuranceProductID);
        //    var packageInsuranceProducts = ServiceFactory.InsuranceProductsServiceInstance.LoadPackageInsuranceProductsBy(sellerInsuranceProductID).ToList();//打包的基础产品列表
        //    var notPackageInsuranceProducts = ServiceFactory.InsuranceProductsServiceInstance.LoadNotPackageInsuranceProductsBy(sellerInsuranceProductID).ToList();//非打包的基础产品列表
        //    if (packageInsuranceProducts.Any())//打包产品 都只有一个
        //    {
        //        for (int i = 0; i < packageInsuranceProducts.Count; i++)
        //        {
        //            var insuranceProduct = packageInsuranceProducts[i];
        //            var insuranceProductPackage = insuranceProduct.InsuranceProductPackageMapping.FirstOrDefault(o => o.InsuranceProductId == insuranceProduct.ID);//打包产品
        //            var entity = new InsuranceProductSnapshoot
        //            {
        //                SellerInsuranceProductID = sellerInsuranceProductID,
        //                SellerInsuranceProductName = sellerInsuranceProduct.ProductName,
        //                InsuranceProductPackageID = insuranceProductPackage != null ? insuranceProductPackage.InsuranceProductPackageId : 0,
        //                InsuranceProductPackageName = insuranceProductPackage != null ? insuranceProductPackage.InsuranceProductPackage.ProductPackageName : "",
        //                //InsuranceProductOrderID = insuranceProductOrderID,
        //                InsuranceProductOrderNo = insuranceProductOrderNo,
        //                //IsCardProduct = insuranceProduct.IsCardProduct.Value,
        //                InsuranceProductNo = insuranceProduct.InsuranceProductNo,
        //                //InsuranceProductCategory = insuranceProduct.InsuranceProductCategory.Value,
        //                ProductName = insuranceProduct.ProductName,
        //                //WaitDays = insuranceProduct.WaitDays.Value,
        //                //InsuranceDevice = insuranceProduct.InsuranceDevice.Value,
        //                //InsuranceDeviceType = insuranceProduct.InsuranceDeviceType.Value,
        //               // PolicyPeriodUnit = insuranceProduct.PolicyPeriodUnit.Value,
        //                //PolicyPeriod = insuranceProduct.PolicyPeriod.Value,
        //                Coverage = insuranceProduct.Coverage,
        //                //IsAvailable = insuranceProduct.IsAvailable,
        //                //CreateBy = insuranceProduct.CreateBy,
        //                CreateTime = insuranceProduct.CreateTime,
        //                //LastModifyBy = insuranceProduct.LastModifyBy,
        //                //LastModifyTime = insuranceProduct.LastModifyTime,
        //                ActiveCardInLimitDays = insuranceProductPackage != null ? insuranceProductPackage.InsuranceProductPackage.ActiveCardInLimitDays : 0
        //            };
        //            result = AddEntities(entity).ID > 0;
        //        }
        //    }
        //    if (notPackageInsuranceProducts.Any())//非打包产品
        //    {
        //        for (int i = 0; i < notPackageInsuranceProducts.Count; i++)
        //        {
        //            var insuranceProduct = notPackageInsuranceProducts[i];
        //            var entity = new InsuranceProductSnapshoot
        //            {
        //                SellerInsuranceProductID = sellerInsuranceProductID,
        //                SellerInsuranceProductName = sellerInsuranceProduct.ProductName,
        //               // InsuranceProductOrderID = insuranceProductOrderID,
        //                InsuranceProductOrderNo = insuranceProductOrderNo,
        //                //IsCardProduct = insuranceProduct.IsCardProduct.Value,
        //                InsuranceProductNo = insuranceProduct.InsuranceProductNo,
        //               // InsuranceProductCategory = insuranceProduct.InsuranceProductCategory.Value,
        //                ProductName = insuranceProduct.ProductName,
        //                //WaitDays = insuranceProduct.WaitDays.Value,
        //               // InsuranceDevice = insuranceProduct.InsuranceDevice.Value,
        //                //InsuranceDeviceType = insuranceProduct.InsuranceDeviceType.Value,
        //               // PolicyPeriodUnit = insuranceProduct.PolicyPeriodUnit.Value,
        //                //PolicyPeriod = insuranceProduct.PolicyPeriod.Value,
        //                Coverage = insuranceProduct.Coverage,
        //                //IsAvailable = insuranceProduct.IsAvailable,
        //                //CreateBy = insuranceProduct.CreateBy,
        //                CreateTime = insuranceProduct.CreateTime,
        //                //LastModifyBy = insuranceProduct.LastModifyBy,
        //                //LastModifyTime = insuranceProduct.LastModifyTime,
        //                ActiveCardInLimitDays = Int32.MaxValue
        //            };
        //            result = AddEntities(entity).ID > 0;
        //        }
        //    }
        //    return result;
        //}
        //public IQueryable<InsuranceProductSnapshoot> GetInsuranceProductSnapshoot(string insuranceProductOrderNo,
        //    long insuranceProductID)
        //{
        //    return
        //        LoadEntities(
        //            o =>
        //                o.InsuranceProductOrderNo.Equals(insuranceProductOrderNo) &&
        //                o.InsuranceProductID == insuranceProductID).AsNoTracking();
        //}
    }
}